# -*- coding: utf-8 -*-
from django.db import models
# Create your models here.
from django.urls import reverse
from django import forms

class ProcessTask(models.Model):

    name=models.CharField(verbose_name=u'通道名称', max_length=128, help_text=u'相关的通道信息',default = u'channel_0')
    video_status_chioce = (
                       (0,u'实时视频流'),
                       (1,u'取监控设备录像'),
                       (2,u'本地文件'),
                       (3,u'未知'),
                       )
    
    video_type = models.IntegerField(choices=video_status_chioce, verbose_name=u'视频类型', default=0)
    
    # 新增字段 
    # stream_id  ip  port  dev_type  protocol   url_or_file  stream_type  plan_id 
    #实时流
    
    vender_choice = (
            (0,u'海康'),
            (1,u'大华'),
            (2,u'宇视'),
            (3,u'其它'),
            )

    vender = models.IntegerField(choices=vender_choice, verbose_name=u'厂家', default=0)
    
    user = models.CharField(max_length=20, verbose_name=u'登录账号', help_text='登录账号',default ='admin', blank=True, null=True)
    passwd = models.CharField(max_length=20, verbose_name=u'登录密码', help_text='登录密码', blank=True, null=True)  #widget=forms.PasswordInput,
    
    ip_number = models.CharField(max_length=19, verbose_name=u'IP地址', help_text='IP地址',default ='127.0.0.1', blank=True, null=True)
    stream_port = models.IntegerField(verbose_name=u'端口号',default=554)
    
    idle_model = models.BooleanField(verbose_name=u'通道状态', default=True)
    
    # local_video_file = FileField()
    # real_time_stream 
    
    channel = models.IntegerField(verbose_name=u'通道号', help_text='通道号',default = 0)
    #concentrate_rate= models.IntegerField(verbose_name='类型')    #浓缩进度  
    
    create_time = models.DateTimeField(verbose_name=u'创建时间',auto_now=True)
    
    #task_id = models.IntegerField(verbose_name='任务号', help_text='任务号',default = 0)
    
    #stream_id=models.CharField(verbose_name='视频ID', max_length=128, help_text='视频ID',default = u'0')
    #protocol_type = 
    #'id','name','video_type','ip_number','idle_model','channel','create_time',''
    
    class Meta:
        #proxy = True
        verbose_name: u"通道"
        verbose_name_plural = u'通道列表'

    def __str__(self):
        return self.name
    #基本的逻辑设置 
    #def set_basic_logic(self):
    # if 2 == self.video_status_chioce:

class TaskPlan(models.Model):
    name =models.CharField(verbose_name=u'任务名称', max_length=128, help_text=u'相关的任务名称信息',default =u'任务0')
    start_time = models.DateTimeField(verbose_name=u'开始时间')
    finish_time = models.DateTimeField(verbose_name=u'结束时间')
    
    cycle_model = models.BooleanField(verbose_name=u'是否循环', default=True)
    cycle_week = models.CharField(max_length=19, verbose_name=u'每周循环天数', help_text='每周循环天数',default ='0x00', blank=True, null=True)
    
    class Meta:
        #proxy = True # 使用代理
        verbose_name: u"任务"
        verbose_name_plural = u'任务计划'

    def __str__(self):
        return self.name


class Video(models.Model):
    #被传到`MEDIA_ROOT/video/2015/01/30`目录，增加了一个时间划分
    #name = models.FileField(verbose_name=u'视频', max_length=128, help_text=u'视频名称')
    video = models.FileField(verbose_name=u'视频', upload_to='video/%Y/%m/%d/')
    title = models.ForeignKey(ProcessTask,verbose_name=u'通道名称', on_delete=models.SET_NULL, blank=False, null=True, )
    class Meta:
        #proxy = True # 使用代理
        verbose_name: u"视频"
        verbose_name_plural = u'视频管理'
    
    def __str__(self):
        return self.video.path





'''
通道列表
任务计划
任务搜索
导出任务列表 
上传视频
'''